package com.minxyz.stock.repository;

import com.minxyz.stock.entity.Stock;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface StockRepository extends JpaRepository<Stock, Integer> {

    //扣减库存操作返回操作行数,返回0的时候表示扣减失败了
    @Modifying
    @Query("update Stock s set s.stock=s.stock-10 where s.id=?1 and s.stock>=10")
    int update(int id);

}
